package com.freewater.springboot.demo.aop.api.advices.comprehensive;

import com.freewater.springboot.demo.aop.api.advices.afterreturn.SimpleAfterReturningAdvice;
import com.freewater.springboot.demo.aop.api.advices.afterthrow.SimpleThrowing;
import com.freewater.springboot.demo.aop.api.advices.around.SimpleAroundAdvice;
import com.freewater.springboot.demo.aop.api.advices.before.SimpleBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

public class Main {
    public static void main(String[] args) {
        ProxyFactory proxyFactory = new ProxyFactory();
        // 先添加环绕通知
        proxyFactory.addAdvice(new SimpleAroundAdvice());
        // 添加后置返回通知
        proxyFactory.addAdvice(new SimpleAfterReturningAdvice());
        // 添加前置通知
        proxyFactory.addAdvice(new SimpleBeforeAdvice());
        // 添加异常通知
        proxyFactory.addAdvice(new SimpleThrowing());
        proxyFactory.setTarget(new CalculatorImpl());
        Calculator proxy = (Calculator) proxyFactory.getProxy();
        int add = proxy.add(1, 5);
        System.out.println("计算的值：---------" + add);
    }
}
